<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends My_Controller{

    public function __construct()
    {
        parent::__construct();
        $this->load->model("User_model","user");
    }

    /**
     *------------------------------------------------------------------------------------------------------------------
     * @title：用户登录接口
     * @action：/login/do_login
     * @method：GET
     * @param：loginName，类型：STRING，必须：YES
     * @param：password，类型：STRING，必须：YES
     * @author:：柏凯
     *------------------------------------------------------------------------------------------------------------------
     */
    public function do_login()
    {
        $params['loginName']=trim($this->queryData["loginName"]);
        $params['password']=trim($this->queryData["password"]);
      
        $validate = new Validate([
            'loginName' => 'require|string',
            'password'=>'require|string',
        ]);
        if (!$validate->check($params)) {
            $this->errorCode = 50003;
            $this->errorMessage = $validate->getError();
            $this->createApi();
            exit;
        }
        $result=$this->user->login($params['loginName'],$params['password']);
        if(in_array($result, ['50012','50013'])){
                $this->errorCode = $result;
                $this->createApi();exit;
            }
        if(empty($result))
        {
            $this->errorCode = 50011;
            $this->errorMessage = $validate->getError();
            $this->createApi();
            exit;
        }
        $this->createApi($result);
        exit;
        
    }

    public function logout()
    {
        $token=trim($this->queryData["token"]);
        if(!$token){
            $this->errorCode = 50003;
            $this->createApi();exit();
        }
        $userInfo = $this->user->getUserInfoByToken($token);
        if(empty($userInfo)){
            $this->errorCode = 50006;
            $this->createApi(); exit();
        }
        $AccountID = $userInfo['AccountID'];
        $res = $this->user->logout($AccountID);
        $this->createApi();
    }
   
}

/* End of file login.php */
/* Location: ./application/controllers/login.php */
